<template>
  <div>
    <jxf-titletip :title="title" @refreshPage="refreshFuc"></jxf-titletip>
    <el-card class="jxf-table-card mt20">
      <div slot="header" class="clearfix">
        <span>数据列表</span>
      </div>
      <jxf-table class="" :table="dataTable">
        <template slot="createTime" slot-scope="consoleInfo">
          <div>{{consoleInfo.row.createTime ? FormatDate.timeFormat(consoleInfo.row.createTime) : ""}}</div>
        </template>
      </jxf-table>
    </el-card>
    <jxf-pagination class="mt20" :pageTotal="pageTotal" :currentPage.sync='currentPage' :pageSize.sync="pageSize"
                    @currentPageChange="currentPageChange" @pageSizeChange="pageSizeChange"></jxf-pagination>
  </div>
</template>

<script>
  import FormatDate from '@/assets/js/formatDate'
    export default {
        name: "LoginLog",
        data() {
          return {
            title: '登录日志',
            FormatDate: FormatDate,
            dataTable: {
              border:true,
              loading:false,
              hasSelect:false,
              tr: [
                {
                  id: '1',
                  label: '时间',
                  show: 'template',
                  prop: 'createTime'
                },
                {
                  id: '2',
                  label: 'IP',
                  prop: 'ipAddress'
                },
                {
                  id: '3',
                  label: '地区',
                  prop: 'area'
                },
                {
                  id: '11',
                  label: '浏览器',
                  prop: 'browser'
                }
              ],
              data: []
            },
            pageTotal:0,
            pageSize:10,
            currentPage:1
          }
        },
        methods: {
          refreshFuc() {
            this.currentPage = 1;
            this.pageSize = 10;
            this.getData();
          },
          getData() {
            let data = {
              pageNum: this.currentPage,
              pageSize: this.pageSize
            }
            ajax.post(apis.home.getConsole, data).then(result => {
              if(result.code == "10000000") {
                this.dataTable.data = result.data.dataList;
                this.pageTotal = result.data.total
              } else {
                this.$message.error(result.message)
              }
            })
          },
          // 切换页面
          currentPageChange(pageNo) {
            this.currentPage = pageNo
            this.getData()
          },
          // 切换页面条数
          pageSizeChange(pageNo) {
            this.pageSize = pageNo
            this.getData()
          },
        },
        created() {
          this.getData()
        }
    }
</script>

<style lang="scss" scoped>

</style>
